import { ref} from 'vue'
import { defineStore } from 'pinia'

export const useSettingStore = defineStore('setting', () => {
    const settingShow = ref(false) //弹框是否显示
    const isScale = ref(true)//是否进行全局适配
    const indexConfig = ref({
        leftBottomSwiper:true,//左下轮播
        rightBottomSwiper:true//右下轮播
    })

    const defaultOption = ref({
        step:4,//数值越大滚动越快
        hover:true,//是否鼠标悬停stop
        wheel:false,//在开启鼠标悬停的情况下是否开启滚轮滚动，默认关闭
        openWatch:true,//开启数据实时监控刷新dom
        direction:1,//0向下，1向上，2向左，3向右
        limitScrollNum:4,//开始无缝滚动的数据量 this.dataList.length
        singleHeight:0,//单步运动停止高度（默认值0是无缝不停止的滚动）direction =>0/1
        singleWidth:0,//单步运动停止高度（默认值0是无缝不停止的滚动）direction =>2/3
        singleWaitTime:3000// 单步运动停止的时间(默认值1000ms)
    })
    /**
     * 设置是否展示设置弹窗
     * @param flag 
     */
    function setSettingShow(flag:boolean){
        settingShow.value =flag
    }
    /**
     * 设置是否自适应选项
     * @param flag 
     */
    function setIsScale (flag:boolean){
        isScale.value =flag
        setSettingData()
    }

    function setIndexConfig(config:any){
        indexConfig.value = config
        localStorage.setItem('MyVisual-indexConfig',JSON.stringify(indexConfig.value))
    }

    function initSetting(){
        let settingData:any =localStorage.getItem('MyVisual-settingData')
        if(settingData){
            settingData =JSON.parse(settingData)
            setIsScale(settingData.isScale)
        }

        let settingIndexConfig = localStorage.getItem('MyVisual-indexConfig')
        if(settingIndexConfig){
            settingIndexConfig =JSON.parse(settingIndexConfig)
            setIndexConfig(settingIndexConfig)
        }
    }

    function setSettingData(){
        localStorage.setItem('MyVisual-settingData',JSON.stringify({
            isScale:isScale.value
        }))
    }

    return { settingShow,setSettingShow,isScale,setIsScale,initSetting,setSettingData,defaultOption,indexConfig,setIndexConfig }
  })